<?php
class Usuario {
	private $id = 0;
	private $nombre;
	private $apellidoMaterno;
	private $apellidoPaterno;
	private $rol;
	private $mail;
	private $password;

	public function toDbArray() {
		return array (
			'USUARIO_MAIL' => $this->mail,
			'USUARIO_PASSWORD' => $this->password,
			'ROL_ID' => $this->rol,
			'USUARIO_NOMBRE' => $this->nombre,
			'USUARIO_APELLIDO_PATERNO' => $this->apellidoPaterno,
			'USUARIO_APELLIDO_MATERNO' => $this->apellidoMaterno
		);

	}

	public function getApellidos() {
		return $this->apellidoPaterno . " " . $this->apellidoMaterno;
	}

	public function getPassword() {
		return $this->password;
	}

	public function setPassword($value) {
		if (strlen($value) < 6) {
			throw new Exception('El password debe ser menor o igual a 6');
		}
		$this->password = $value;
	}

	public function getMail() {
		return $this->mail;
	}

	public function setMail($value) {
		$validButRare = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
		if (!eregi($validButRare, $value)) {
			throw new Exception('El email no es valido');
		}
		$this->mail = $value;
	}

	public function getRol() {
		return $this->rol;
	}

	public function setRol($value) {
		if (!is_numeric($value)) {
			throw new Exception('No has elegido rol para el usuario.');
		}
		$this->rol = $value;
	}

	public function getApellidoPaterno() {
		return $this->apellidoPaterno;
	}

	public function setApellidoPaterno($value) {
		$this->apellidoPaterno = $value;
	}

	public function getApellidoMaterno() {
		return $this->apellidoMaterno;
	}

	public function setApellidoMaterno($value) {
		$this->apellidoMaterno = $value;
	}

	public function getNombre() {
		return $this->nombre;
	}

	public function setNombre($value) {
		if ($value == "") {
			throw new Exception('El nombre no puede ser vacio para un usuario.');
		}
		$this->nombre = $value;
	}

	public function getId() {
		return $this->id;
	}

	public function setId($value) {
		$this->id = $value;
	}

	function User() {
	}
}
?>